'use strict';


class command {
    constructor(argv) {
        if (!argv) {
            throw new Error('class command 参数不能为空！')
        }
        if (!Array.isArray(argv)) {
            throw new Error('class command 参数必须为数组！')
        }
        if (argv.length < 1) {
            throw new Error('class command 参数数组不能为空！')
        }
        // 开启微任务队列，使用异步执行
        this._argv = argv

        let runner = new Promise((resolve, reject) => {
            let chain = Promise.resolve()
            chain = chain.then(() => this.initArgs())
            chain = chain.then(() => this.init())
            chain = chain.then(() => this.exec())
            chain.catch((err) => console.error(err))
        })
    }

    initArgs() {
        this.argv = this._argv.slice(0, this._argv.length - 1)
        this.cmd = this._argv[this._argv.length - 1]
    }

    init() {
        throw new Error('init必须重写！')
    }

    exec() {
        throw new Error('exec必须重写！')
    }
}
module.exports = command;
